<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./template.xhtml">

            <ui:define name="title">
                Báo cáo thẻ cào
            </ui:define>

            <ui:define name="content">
                <h:form id="inputForm">
                    <p:panel>
                        <h:panelGrid columns="4">
                            Ngày bắt đầu* 
                            <p:calendar value="#{scratchCardReportBean.startTime}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày bắt đầu"> 
                            </p:calendar>
                            Ngày kết thúc* 
                            <p:calendar value="#{scratchCardReportBean.endTime}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày kết thúc"/>
                            Khung thời gian từ
                            <p:inputMask value="#{scratchCardReportBean.startWindow}" mask="99:99:99" />
                            Đến
                            <p:inputMask value="#{scratchCardReportBean.endWindow}" mask="99:99:99"/>

                            Đối tác
                            <p:selectOneMenu value="#{scratchCardReportBean.partnerId}">
                                <f:selectItems value="#{partnerBean.partnerIdMap}"/>
                            </p:selectOneMenu>

                        </h:panelGrid>

                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Truy vấn" action="#{scratchCardReportBean.getReport()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>

                <br/>

                <h:form id="tableForm">
                    <p:dataTable value="#{scratchCardReportBean.list}" var="item" paginator="#{scratchCardReportBean.list.size() >20}" rows="20" >
                        <f:facet name="header">  
                            Doanh thu theo ngày
                        </f:facet>
                        <p:column headerText="Ngày giao dịch" sortBy="#{item.dayStr}">
                            #{item.dayStr}
                        </p:column>
                        <p:column headerText="Tổng giá trị giao dịch" sortBy="#{item.totalAmount}">
                            <h:outputText value="#{item.totalAmount}">
                                <f:convertNumber pattern="#,###,###,##0"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Tổng số giao dịch" sortBy="#{item.totalTransactions}">
                            #{item.totalTransactions}
                        </p:column>
                    </p:dataTable>

                    <br/>

                    <p:dataTable value="#{scratchCardReportBean.transactionResults}" var="item" paginator="#{scratchCardReportBean.transactionResults.size() >20}" rows="20" >
                        <f:facet name="header">  
                            Các lỗi giao dịch
                        </f:facet>
                        <p:column headerText="Tổng số giao dịch" sortBy="#{item.count}">
                            #{item.count}
                        </p:column>
                        <p:column headerText="Mã lỗi" sortBy="#{item.transErr}">
                            #{item.transErr}
                        </p:column>
                        <p:column headerText="Lỗi giao dịch" sortBy="#{item.transErrDetail}">
                            #{item.transErrDetail}
                        </p:column>
                    </p:dataTable>

                    <br/>

                    <p:dataTable value="#{scratchCardReportBean.partnerRevenues}" var="item" paginator="#{scratchCardReportBean.partnerRevenues.size() >20}" rows="20" >
                        <f:facet name="header">  
                            Doanh thu theo mệnh giá thẻ
                        </f:facet>
                        <p:column headerText="Tổng số giao dịch" sortBy="#{item.count}">
                            #{item.count}
                        </p:column>
                        <p:column headerText="Mệnh giá" sortBy="#{item.amount}">
                            <h:outputText value="#{item.amount}">
                                <f:convertNumber pattern="#,###,###,##0"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Tổng giá trị giao dịch" sortBy="#{item.totalAmount}">
                            <h:outputText value="#{item.totalAmount}">
                                <f:convertNumber pattern="#,###,###,##0"/>
                            </h:outputText>
                        </p:column>
                    </p:dataTable>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
